package cn.itcast.hotel.config;

import cn.itcast.hotel.constatnts.MqConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 声明交换机和队列
 */
@Configuration
public class MqConfig {
    //声明交换机
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(MqConstants.HOTEL_EXCHANGE);
    }

    //声明insert队列 , 因为新增和修改为同一种效果,固两者使用一种队列
    @Bean
    public Queue insertQueue(){
        return new Queue(MqConstants.HOTEL_INSERT_QUEUE);
    }

    //声明delete队列
    @Bean
    public Queue deleteQueue(){
        return new Queue(MqConstants.HOTEL_DELETE_QUEUE);
    }

    //绑定insert队列和交换机
    @Bean
    public Binding bindInsertQueueAndExchange(){
        return BindingBuilder.bind(insertQueue()).to(topicExchange()).with(MqConstants.HOTEL_INSERT_KEY);
    }

    //绑定delete队列和交换机
    @Bean
    public Binding bindDeleteQueueAndExchange(){
        return BindingBuilder.bind(deleteQueue()).to(topicExchange()).with(MqConstants.HOTEL_DELETE_KEY);
    }
}
